package com.zhxh.nzpos.utils;

import android.content.Context;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;

/**
 * 持久化相应参数
 * 
 * @author wangzt
 *
 */
public class PersistenceUtil {

	private static final String NZ_POS_PREFERENCE = "nz_pos_preference";
	private static final String CARD_ID = "card_id"; //操作卡号
	private static final String CARD_PASSWORD = "card_password"; // 操作卡密码
	private static final String POS_ID = "pos_id"; // pos机ID
	
	/**
	 * 进入系统时刷卡，保存刷卡信息
	 * 
	 * @param cardId
	 * @param password
	 * @param context
	 */
	public static void saveOperatorCard(String cardId, String password, Context context) {
		Editor editor = context.getSharedPreferences(NZ_POS_PREFERENCE, Context.MODE_PRIVATE).edit();
		if (editor != null && !TextUtils.isEmpty(cardId)) {
			editor.putString(CARD_ID, cardId);
			editor.putString(CARD_PASSWORD, password);
			editor.commit();
		}
	}
	
	/**
	 * 返回操作员卡号
	 * @param context
	 * @return
	 */
	public static String getOperatorCard(Context context) {
		return context.getSharedPreferences(NZ_POS_PREFERENCE, Context.MODE_PRIVATE).getString(CARD_ID, "");
	}
	
	/**
	 * 保存Pos机ID
	 * 
	 * @param posId
	 * @param context
	 */
	public static void savePosId(String posId, Context context) {
		Editor editor = context.getSharedPreferences(NZ_POS_PREFERENCE, Context.MODE_PRIVATE).edit();
		if (editor != null && !TextUtils.isEmpty(posId)) {
			editor.putString(POS_ID, posId);
			editor.commit();
		}
	}
	
	/**
	 * 获得Pos机ID
	 * 
	 * @param context
	 * @return
	 */
	public static String getPosId(Context context) {
		return context.getSharedPreferences(NZ_POS_PREFERENCE, Context.MODE_PRIVATE).getString(POS_ID, "");
	}
	
	private PersistenceUtil() {
	}
}
